package com.qf.controller;

import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkUser")
public class CheckUserServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //先校验激活码



        //1)获取用户名
        //$.get("checkUser?username="+this.value+""
        String username = request.getParameter("username");
        //System.out.println("username:"+username);

        //2)调用业务接口
        UserService userService = new UserServiceImpl() ;
        boolean flag = userService.checkUser(username);
        //判断
        if(flag){
            //可以注册
            //响应给前台
            response.getWriter().write("0");
        }else{
            response.getWriter().write("1");
        }


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);

    }
}
